﻿using UFIDA.U9.CBO.FI.Enums;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForPaytonull : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //请款单
            UFIDA.U9.AP.Payment.PayReqFundHead pay = key.GetEntity() as UFIDA.U9.AP.Payment.PayReqFundHead;
            if (pay == null) return;

            #region 复制清空请款单:附件,单据状态,审批意见
            //清空审批意见
            if(pay.OriginalData.DocStatus == InDirectHandleBillDocStatusEnum.Approved && pay.DocStatus == InDirectHandleBillDocStatusEnum.Open)
            {
                if (pay.DescFlexField.PrivateDescSeg2 != "" || pay.DescFlexField.PrivateDescSeg2 != null)
                {
                    pay.DescFlexField.PrivateDescSeg2 = "";
                }
                //清空附件
                if (pay.DescFlexField.PrivateDescSeg4 != "" || pay.DescFlexField.PrivateDescSeg4 != null)
                {
                    pay.DescFlexField.PrivateDescSeg4 = "";
                }
                //清空oa标识
                if (pay.DescFlexField.PubDescSeg6 != "" || pay.DescFlexField.PubDescSeg6 != null)
                {
                    pay.DescFlexField.PubDescSeg6 = "";
                }
            }
            if(pay.DocStatus == InDirectHandleBillDocStatusEnum.Open)
            {
                if (pay.DescFlexField.PrivateDescSeg2 != "" || pay.DescFlexField.PrivateDescSeg2 != null)
                {
                    pay.DescFlexField.PrivateDescSeg2 = "";
                }
                //清空附件
                if (pay.DescFlexField.PrivateDescSeg4 != "" || pay.DescFlexField.PrivateDescSeg4 != null)
                {
                    pay.DescFlexField.PrivateDescSeg4 = "";
                }
                //清空oa标识
                if (pay.DescFlexField.PubDescSeg6 != "" || pay.DescFlexField.PubDescSeg6 != null)
                {
                    pay.DescFlexField.PubDescSeg6 = "";
                }
            }
            //单据标识
            if (pay.OriginalData.DocStatus ==InDirectHandleBillDocStatusEnum.Open && pay.DocStatus == InDirectHandleBillDocStatusEnum.InApprove)
            {
                int n = 1;
                if (pay.DescFlexField.PubDescSeg8 == "")
                {
                    
                    pay.DescFlexField.PubDescSeg8 = n.ToString();
                }
                else
                {
                    pay.DescFlexField.PubDescSeg8 = (decimal.Parse(pay.DescFlexField.PubDescSeg8) + n).ToString();
                }
            }


            #endregion

        }

    }
}
